$(function() {
	var browser = {
		versions: function() {
			var u = navigator.userAgent,
				app = navigator.appVersion;
			return {
				mobile: !!u.match(/AppleWebKit.*Mobile.*/),
				ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
				android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
				iPhone: u.indexOf('iPhone') > -1,
				iPad: u.indexOf('iPad') > -1,
				webApp: u.indexOf('Safari') == -1,
				weiXin: !!u.match(/MicroMessenger/i)
			};
		}(),
	}
	function getTargetUrl() {
		var url = location.search;
		var theTarget = new Object();
		if(url.indexOf("?") != -1) {
			var str = url.substr(1);
			strs = str.split("&");
			for(var i = 0; i < strs.length; i++) {
				theTarget[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
			}
		}
		return theTarget;
	}
	var Request = new Object(),
		goUrl = Request["goApp"],
		targetUrl = "sharenanguache://data/schemepage=home";
	Request = getTargetUrl();
	if(goUrl != null && goUrl != "") {
		targetUrl = "sharenanguache://data/schemepage=" + gourl;
	}
	var oDownloadBtn = $('.download-btn'),
		downloadUrl = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.mrocker.salon.app',
		systemName = navigator.appVersion.toLowerCase(),
		version,
		promptImg = $('.prompt-img');
	console.log(systemName);
	if(browser.versions.mobile && browser.versions.weiXin) {
		promptImg.css('display','block');
	}else if(browser.versions.iPhone) {
		promptImg.css('display','none');
		/*var loadDateTime = new Date();
		window.setTimeout(function() {
			var timeOutDateTime = new Date();
			if(timeOutDateTime - loadDateTime < 5000) {
				window.location = downloadUrl;
			} else {
				window.close();
			}
		}, 25);*/
		window.location = targetUrl;
	}else if(browser.versions.android) {
		promptImg.css('display','none');
		var ifr = document.createElement('iframe');
		document.body.appendChild(ifr);
		ifr.style.display = 'none';
		ifr.src = targetUrl;
		window.setTimeout(function() {
			document.body.removeChild(ifr);
		}, 2000)
	} else if(browser.versions.mobile === false){
		promptImg.css('display','none');
	}
	oDownloadBtn.click(function() {
		/*if(browser.versions.mobile && browser.versions.weiXin) {
			if(browser.versions.mobile && browser.versions.iPhone) {
				window.location = downloadUrl;
			} else if(browser.versions.mobile && browser.versions.android) {
				window.location = downloadUrl;
			}
		} else if(browser.versions.mobile && browser.versions.iPhone) {
			window.location = iosUrl;
		} else if(browser.versions.mobile && browser.versions.android) {
			window.location = androidUrl;
		}*/
		window.location = downloadUrl;
	});
})